package edu.gatech.asthma.ui_support.symptoms;

import java.util.List;

import edu.gatech.asthma.R;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;


/**
 * A custom Adapter that handles the ListView of symptoms presented on the record symptoms page
 *
 */
public class SymptomsArrayAdapter extends ArrayAdapter<SymptomsListItem>{
	
	Context context;
	int layoutResourceId;
	List<SymptomsListItem> symptoms;

	public SymptomsArrayAdapter(Context c, int l, List<SymptomsListItem> s) {
		super(c, l, s);
		context = c;
		layoutResourceId = l;
		symptoms = s;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		//if convertView is non-null, ListView is asking you to recycle the row layout (simply update its contents)
		if (convertView == null) {
			LayoutInflater inflater = ((Activity) context).getLayoutInflater();
			convertView = inflater.inflate(layoutResourceId,  parent, false);
		}
		
		SymptomsListItem item = symptoms.get(position);
		
		//set the symptom text and tag in this within the ListView
		TextView text = (TextView) convertView.findViewById(R.id.symptom_item_text);
		text.setText(item.getName());
		convertView.setTag(item);
		return convertView;
	}

}
